package com.xwh.system.controller;

import com.xwh.core.controller.BaseController;
import com.xwh.core.dto.Result;
import com.xwh.system.entity.SysFile;
import com.xwh.system.service.SysFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件管理
 *
 * @author xwh
 **/
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
@Tag(name = "系统:文件管理")
public class FileController extends BaseController {

    final SysFileService sysFileService;

    @PostMapping("ftpUpload")
    @Operation(summary = "通过ftp上传文件", description = "通过ftp上传文件", tags = {"file"})
    public Result ftpUpload(MultipartFile file) {
        SysFile fileBean = sysFileService.getFileBean(file);
        try {
            sysFileService.ftpUpload(fileBean, file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return Result.success();
    }
}
